<template>
  <h1>员工列表练习</h1>
  <input type="text" placeholder="请输入员工姓名" v-model="staff.name">
  <input type="text" placeholder="请输入员工工资" v-model="staff.salary">
  <input type="text" placeholder="请输入员工岗位" v-model="staff.post">
  <button @click="f">点我添加</button>
  <table border="1px">
    <tr>
      <th>编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(item,index) in arr">
      <td>{{index+1}}</td>
      <td>{{item.name}}</td>
      <td>{{item.salary}}</td>
      <td>{{item.post}}</td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const arr = ref([]);
const staff = ref({
  name: '',
  salary: '',
  post: ''
})
const f = ()=>{
  if(staff.value.name.trim()==''||staff.value.salary.trim()==''||staff.value.post.trim()==''){
    alert('请输入员工信息!');
    return;
  }
  arr.value.push(staff.value);
  staff.value = {name: '',salary: '',post: ''};
}
</script>

<style scoped>

</style>